package com.panda.crud.logic.delete.auto.fill.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panda.crud.logic.delete.auto.fill.entity.Result;
import com.panda.crud.logic.delete.auto.fill.entity.User;
import com.panda.crud.logic.delete.auto.fill.entity.UserQuery;
import com.panda.crud.logic.delete.auto.fill.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("user")
public class UsersController {
    @Resource
    private UserService userService;

    @PostMapping(value = "pageUsers")
    public Result<Page<User>> pageUsers(@RequestBody UserQuery userQuery) {
        return userService.pageUsers(userQuery);
    }

    @GetMapping(value = "queryByUserId")
    public Result<User> queryByUserId(long userId) {
        return Result.success(userService.queryByUserId(userId));
    }

    @PostMapping(value = "updateAllTable")
    public Result<Boolean> updateAllTable() {
        return Result.success(userService.updateAllTable());
    }

    @PostMapping(value = "deleteAllTable")
    public Result<Boolean> deleteAllTable() {
        return Result.success(userService.deleteAllTable());
    }

    @PostMapping(value = "getUserByTableName")
    public Result<List<User>> getUserByTableName(@RequestBody UserQuery userQuery) {
        return Result.success(userService.getUserByTableName(userQuery));
    }
}
